//
//  HWGameLiveProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/1/5.
//

import UIKit

class HWGameLiveProtocol: NSObject {
    var models:[HWGameLiveListModel]?
    var jumpToLiveRoom:((_:HWGameLiveListModel)->())?
}

extension HWGameLiveProtocol:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.jumpToLiveRoom?(models?[indexPath.row] ?? HWGameLiveListModel())
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 11*widthScale, left: 12*widthScale, bottom: 0, right: 12*widthScale)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return models?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 172*widthScale, height: 129*widthScale)
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let gameLiveCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HWGameLiveCell", for: indexPath) as! HWGameLiveCell
        gameLiveCell.model = self.models?[indexPath.row]
        return gameLiveCell
    }
    
    
}
